import React, { Component ,Suspense} from 'react'
import {Switch,Route,Redirect} from "react-router-dom"
import Context from "../utils/Context"
export class RouterView extends Component {
    render() {
        let {routes} = this.props
        return (
            <Suspense fallback={"路由加载中"}>
                <Switch>
                    {
                        routes&&routes.map((item,index)=>{
                            return <Route key= {index} path={item.path} render={(routerProps)=>{
                                return item.redirect? <Redirect to={item.redirect}/>:
                                <Context.Provider value={routerProps}>
                                    <item.component {...routerProps} routes={item.children}/>
                                </Context.Provider>
                               
                            }}/>
                        })
                    }
                </Switch>
            </Suspense>
        )
    }
}

export default RouterView
